<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
<link rel="stylesheet" href="http://jquerymobile.com/demos/1.0b1/docs/_assets/css/jqm-docs.css" />
<link rel="stylesheet" href="/css/page42.css" />
<script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
// getting url param.
function getURLParameter(name) {
	var s = decodeURI(
		(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
	);
	// Create a regular expression to search all +s in the string
	var lsRegExp = /\+/g;
	// Return the decoded string
	return unescape(String(s).replace(lsRegExp, " ")); 
}

$(document).ready(function() {

	var search = getURLParameter('search');
	if (search == 'null') 
		search = "jarrettist"

	$('#search').attr('value', search);
	
	url = "http:\/\/"+search+".tumblr.com/rss";
	//var url = "http://brightsizelifekr.tumblr.com/rss";
	var yql = "http://query.yahooapis.com/v1/public/yql?q=";
	var query = "select * from xml where url = \""+url +"\"";
	yql = yql + encodeURI(query);
	var pttn = /(http:\/\/www.tumblr.com\/audio_file\/[^&]+)/;
	
	$.get(yql, function(d){

		$(d).find('item').each(function(){
			var $item = $(this);
			var title = $item.find('title').text();
			var desc = $item.find('description').text();
			var link = $item.find('link').text();
			var pubDate = $item.find('pubDate').text();
			
			if (pttn.test(desc))
			{
				var file = desc.match(pttn);
				fileURL = file[0]+"?plead=please-dont-download-this-or-our-lawyers-wont-let-us-host-audio";
			
				$("#results").append(
						"<li><a href=\""+fileURL+"\">"+title+"</a> <a href=\""+link+"\"></a></li>"
				);
				$("#results").listview( "refresh" );
			}
		});
	});
});
</script>
<script src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
</head>

<body> 
<div data-role="page">
	<div data-role="header" >
		<h1>Tumblr is an Angel.</h1>
	</div>
	<div data-role="content">
		<div data-role="fieldcontain">
			<form>
				<input type="search" name="search" id="search"  data-inline="true">
				<input type="submit" value="Find Musics" data-inline="true">
			</form>
		</div>
		<ul data-role="listview" id="results"></ul>
	</div>
	<div data-role="footer"><h1>Love from <a href="http://youminkim.tumblr.com/">vegetables</a>.</h1></div> 
</div>
</body> 

</html>


<!--
<body>
	<h1>Tumblr is an angel.</h1>
	<form>

	</form>
	<div id="results"></div>
	<hr>
	<h2>Love.</h2>
</body>
-->